package com.visikard.asynctask;

import android.os.Handler;
import android.os.Message;

import com.visikard.application.UIMessage;
import com.visikard.business.CouponBUS;
import com.visikard.response.BaseResponse;
import com.visikard.response.GetCouponResponse;

public class GetAllCouponTask extends BaseTask {

	public static final int POS_UID = 0;

	public GetAllCouponTask(Handler handler) {
		super(handler);
	}

	public GetAllCouponTask(Handler handler, boolean isShowProgress) {
		super(handler, isShowProgress);
	}

	@Override
	protected Object doBackgroundWork(Object... params) {
		long uid = (Long) params[POS_UID];
		CouponBUS busObj = new CouponBUS();
		return busObj.getAllCoupons(uid);
	}

	@Override
	protected boolean handleResult(Object result) {
		GetCouponResponse response = (GetCouponResponse) result;
		if (response != null) {
			switch (response.getErrorCode()) {
				case BaseResponse.SUCCESS:
					Message successMsg = new Message();
					successMsg.what = UIMessage.MSG_GET_LIST_SUCCESS;
					successMsg.obj = response.getListCoupons();
					mUIHandler.sendMessage(successMsg);
					return true;
			}
		}
		return false;
	}

}
